package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.measuringToolsListPojo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

//定义一个公开访问的接口，即mapper，接口命名规则：表名+Mapp；
@Mapper
public interface measuringToolsListMapp {
    //指定数据库，现用低代码正式数据库
    @DS("newMscLowCodeFormal")
    //定义将接收到的数据分别放入到数据库的哪个字段
    @Insert("insert into ddm_measuring_tool_list(" +
            " create_time, update_time, creator, " +
            "sys_update_user, sys_deleted, establishTime, " +
            "updateTime, number, name, " +
            "name_english, name_russian, specification, " +
            "is_checked, inspection_frequency, is_calibration, " +
            "calibration_cycle, section, `group`, " +
            "id, standard_value, upper_tolerance, " +
            "lower_tolerance, engine_model) " +
            "VALUES (" +
            "#{create_time}, #{update_time}, #{creator}, " +
            "#{sys_update_user}, #{sys_deleted}, #{establishTime}, " +
            "#{updateTime}, #{number}, #{name}, " +
            "#{name_english}, #{name_russian}, #{specification}, " +
            " #{is_checked}, #{inspection_frequency}, #{is_calibration}, " +
            " #{calibration_cycle}, #{section}, #{group}, " +
            "#{id}, #{standard_value}, #{upper_tolerance}, " +
            "#{lower_tolerance}, #{engine_model})")
    //声明insertOne方法不返回任何值
    void insertOne(measuringToolsListPojo pojo);

    //查询计量器具基本信息表中所有的数据
    //指定数据库，现用低代码正式数据库
    @DS("newMscLowCodeFormal")
    //*代表所有字段
    @Select("select * from ddm_measuring_tool_list where sys_deleted=0")
    List<measuringToolsListPojo> queryAll();

    //根据IdUse编辑某一行数据
    //指定数据库，现用低代码正式数据库
    @DS("newMscLowCodeFormal")
    //更新哪些字段的数据
    @Update("update ddm_measuring_tool_list " +
            "set " +
            "id=#{id}," +
            "create_time=#{create_time}," +
            "update_time=#{update_time}," +
            "creator=#{creator}," +
            "sys_update_user=#{sys_update_user}," +
            "sys_deleted=#{sys_deleted}," +
            "establishTime=#{establishTime}," +
            "updateTime=#{updateTime}," +
            "number=#{number}," +
            "name=#{name}," +
            "name_english=#{name_english}," +
            "name_russian=#{name_russian}," +
            "specification=#{specification}," +
            "is_checked=#{is_checked}," +
            "inspection_frequency=#{inspection_frequency}," +
            "is_calibration=#{is_calibration}," +
            "calibration_cycle=#{calibration_cycle}," +
            "section=#{section}," +
            "`group`=#{group}," +
            "standard_value=#{standard_value}, " +
            "upper_tolerance=#{upper_tolerance}, " +
            "lower_tolerance=#{lower_tolerance}, " +
            "engine_model=#{engine_model}" +
            //明确修改的是某一行，而不是将所有行全部修改（如果不写的话会默认修改所有行数据）
            " where id=#{id}")
    void editOneByIdUse(measuringToolsListPojo pojo);

    //根据ID，选择一行数据
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_measuring_tool_list where id=#{id}")
    measuringToolsListPojo selectById(String id);

    //查询某一字段为某一值的所有数据
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_measuring_tool_list where ${filedName}=#{filedVal}")
    List<measuringToolsListPojo> selectByField(String filedName, String filedVal);
}
